﻿using System.ComponentModel;
using System.Globalization;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using Castle.Core.Logging;

namespace Ast.Core
{
    public static class LoggerExtensions
    {
        public static void Win32ErrorFormat(this ILogger logger, string format, params object[] args)
        {
            // MessageBox.Show(System.Environment.StackTrace);

            var message = string.Format(CultureInfo.CurrentCulture, format, args);
            var errorCode = Marshal.GetLastWin32Error();
            var errorMessage = new Win32Exception(errorCode).Message;
            logger.ErrorFormat("{0} - error code {1}: {2}", message, errorCode, errorMessage);
        }
    }
}